<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        /* function Person(name,age){
            this.name = name
            this.age = age
        }
        Person.prototype = {
            constructor:Person,
            sayName(){
                console.log(this.name);
            }
        } */

        // constructor 函数--构造一个对象的函数
        class Person{
            constructor(name,age){
                this.name = name;
                this.age = age
            }
            sayName(){
                console.log(this.name);
            }
        }
        Person.prototype.sayAge = function(){
            console.log(this.age);
        }

        // 不允许以字面量的形式去添加属性的
        /* Person.prototype = {
            sayAge(){
                console.log(this.age);
            }
        } */
        var p = new Person("cheng",19)
        console.log(p);
        p.sayAge()
    </script>
</body>
</html>